import Taro, { Component } from '@tarojs/taro'
import { View, Text} from '@tarojs/components'
import {AtList,AtListItem,AtForm,AtInput,AtButton,AtModal, AtModalHeader, AtModalContent, AtModalAction} from 'taro-ui'
import './wenzhenshezhi.scss'
import reactMixin from 'react-mixin';
import myJs from './wenzhenshezhiJs.js'
import app from '../../../../main.js'

export default class Wenzhenshezhi extends Component {
    config = {
        navigationBarTitleText: '问诊设置'
    }
    constructor () { 
        super(...arguments); 
        this.state = this.getData(); 
    }
    init(){
        this.getDoctor();
        
    }
    afterGetDoctor(){
        let that=this.state.doctor;
        that.is_open_display_order_record==='关闭'?that.is_open_display_order_record=false:that.is_open_display_order_record=true;
        that.is_open_inquiry_direction_order_remind==='关闭'?that.is_open_inquiry_direction_order_remind=false:that.is_open_inquiry_direction_order_remind=true;
        that.is_open_inquiry_no_direction==='关闭'?that.is_open_inquiry_no_direction=false:that.is_open_inquiry_no_direction=true;
        that.is_open_inquiry_direction==='关闭'?that.is_open_inquiry_direction=false:that.is_open_inquiry_direction=true;
        that.is_open_inquiry_group==='关闭'?that.is_open_inquiry_group=false:that.is_open_inquiry_group=true;
        this.setState({
            doctor:this.state.doctor
        });
    }
    beforeUpdateDoctor(data){
        let that=this.state.doctor;
        if(data.inquiry_directional_price===''||data.inquiry_directional_price===null||Number.parseInt(data.inquiry_directional_price)===0){
            app.alertTab('问诊价格不能为空');
            return false;
        }
        if(isNaN(data.inquiry_directional_price)){
          app.alertTab('问诊价格请填写数字类型');
          return false;
        }
        if(data.inquiry_group_price===''||data.inquiry_group_price===null||Number.parseInt(data.inquiry_group_price)===0){
            app.alertTab('团队价格不能为空');
            return false;
        }
        if(isNaN(data.inquiry_group_price)){
          app.alertTab('团队价格请填写数字类型');
          return false;
        }
        that.is_open_display_order_record===true?that.is_open_display_order_record='开通':that.is_open_display_order_record='关闭';
        that.is_open_inquiry_direction_order_remind===true?that.is_open_inquiry_direction_order_remind='开通':that.is_open_inquiry_direction_order_remind='关闭';
        that.is_open_inquiry_no_direction===true?that.is_open_inquiry_no_direction='开通':that.is_open_inquiry_no_direction='关闭';
        that.is_open_inquiry_direction===true?that.is_open_inquiry_direction='开通':that.is_open_inquiry_direction='关闭';
        that.is_open_inquiry_group===true?that.is_open_inquiry_group='开通':that.is_open_inquiry_group='关闭';
        data.id=app.current.id;
        this.setState({
          doctor:this.state.doctor
      });
            return true;
        };
    afterUpdateDoctor(){
        this.navigateTo('../dingxiangwenzhen/dingxiangwenzhen');
    };

    
    render () {
        return (
            <View className='wenzhenshezhi'>
                <AtList>
                    <AtListItem 
                     title='定向问诊通道'
                     isSwitch={true} 
                     switchIsCheck={this.state.doctor.is_open_inquiry_direction}
                     switchColor='#72d021'
                     onSwitchChange={this.handleChange.bind(this,'doctor.is_open_inquiry_direction',!this.state.doctor.is_open_inquiry_direction)}
                     ></AtListItem>
                </AtList>
                <AtForm className=' class_0'>
                    <AtInput 
                    title='问诊价格' 
                    placeholder='请输入价格'
                    value={this.state.doctor.inquiry_directional_price}
                    onChange={this.handleChange.bind(this,'doctor.inquiry_directional_price')}
                    ></AtInput>
                </AtForm>
                <AtList className=' class_1'>
                    <AtListItem 
                    title='非定向问诊通道' 
                    isSwitch={true}
                    switchIsCheck={this.state.doctor.is_open_inquiry_no_direction}
                    switchColor='#72d021'
                    onSwitchChange={this.handleChange.bind(this,'doctor.is_open_inquiry_no_direction',!this.state.doctor.is_open_inquiry_no_direction)}
                    ></AtListItem>
                </AtList>
                <AtList className=' class_2'>
                    <AtListItem 
                    title='定向问诊新订单提醒' 
                    isSwitch={true}
                    switchIsCheck={this.state.doctor.is_open_inquiry_direction_order_remind}
                    switchColor='#72d021'
                    onSwitchChange={this.handleChange.bind(this,'doctor.is_open_inquiry_direction_order_remind',!this.state.doctor.is_open_inquiry_direction_order_remind)}
                    ></AtListItem>
                </AtList>
                <AtList className=' class_3'>
                    <AtListItem 
                    title='团队问诊通道' 
                    isSwitch={true}
                    switchIsCheck={this.state.doctor.is_open_inquiry_group}
                    switchColor='#72d021'
                    onSwitchChange={this.handleChange.bind(this,'doctor.is_open_inquiry_group',!this.state.doctor.is_open_inquiry_group)}
                    ></AtListItem>
                </AtList>
                <AtForm className=' class_4'>
                    <AtInput 
                    title='团队价格' 
                    placeholder='请输入价格'
                    value={this.state.doctor.inquiry_group_price}
                    onChange={this.handleChange.bind(this,'doctor.inquiry_group_price')}
                    ></AtInput>
                </AtForm>
                <AtList className=' class_5'>
                    <AtListItem 
                    title='显示历史订单' 
                    isSwitch={true}
                    switchIsCheck={this.state.doctor.is_open_display_order_record}
                    switchColor='#72d021'
                    onSwitchChange={this.handleChange.bind(this,'doctor.is_open_display_order_record',!this.state.doctor.is_open_display_order_record)}
                    ></AtListItem>
                </AtList>
                <View className=' class_6'>
                    {/* <AtButton className=' class_7' full onClick={this.navigateTo.bind(this,'../dingxiangwenzhen/dingxiangwenzhen')}> */}
                    <AtButton className=' class_7' full onClick={this.updateDoctor.bind(this)}>
                        <Text className=' class_8'>保存</Text>
                    </AtButton>
                </View>
                <AtModal
                isOpened={false}
                title='标题'
                confirmText='确认'
                content='欢迎加入京东凹凸实验室\n\r欢迎加入京东凹凸实验室'
                />
            </View>
        );
    }
}
reactMixin.onClass(Wenzhenshezhi,myJs);